package com.gwcloud.design.create.factory.abstr;

/** 
* @ClassName   : BusinessmanAbstractFactory 
* @author      : ganwei 
* @date        : 2020年6月28日 
* @Description : 抽象工厂模式 
*/
public class BusinessmanAbstractFactory<T extends Fruits> {
	/**
	 * -创建苹果
	 * @param name 指定创建的苹果类路径
	 * @return FruitsApple
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 */
	@SuppressWarnings("unchecked")
	public static <T> T createFruit(String name) throws InstantiationException, IllegalAccessException, ClassNotFoundException{
		if("".equals(name) || name == null){
			return null;
		}
		return (T) Class.forName(name).newInstance();
	}
	
	public static void main(String[] args) {
		try {
			Fruits apple = BusinessmanAbstractFactory.createFruit("com.gwcloud.design.create.factory.abstr.RedApple");
			apple.describe();
			
			Fruits banana = BusinessmanAbstractFactory.createFruit("com.gwcloud.design.create.factory.abstr.BigBanana");
			banana.describe();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
}
